from syslogd.configuration.Configuration import Configuration
from syslogd.status.ServiceController import ServiceController



class ConfWriter(object):
    
    @staticmethod
    def writeConf(status, confObjects):
        
        if status.getStatus():
            status.setStatus(ServiceController.sudoStopSyslogd())
        
        fl = open(Configuration.getSyslogdConfigurationPath(),'w')
        for cObject in confObjects:
            fl.write(cObject.__str__() + '\n')
        fifo = ConfWriter.makeFifoLine()    
        if not any(fifo in cObject.__str__() for cObject in confObjects):
            fl.write(fifo + '\n\n')
        fl.close()
        
    @staticmethod        
    def makeFifoLine():
        return "*.*\t\t\t|" + Configuration.getFifoPath()